package com.sword.springboot.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sword.springboot.bean.User;
import com.sword.springboot.service.UserService;

@Controller
@RequestMapping(value="/manage")
public class UserController {
	
	@Autowired
	private UserService userService;

	@RequestMapping(value="/user.do")
	public String user(Model model)throws Exception{
		List<User> users = userService.getUsers();
		
		model.addAttribute("users", users);
		return "view/manage/userManage_UI";
	}
	
	@RequestMapping(value="/addNewUser.do")
	public String addNewUser(Model model, User user, Integer iniPage) throws Exception {
		Integer id = 0;
		System.out.println("addNewuser.do============================");
		if(iniPage != 1){
			id = userService.addNewUser(user);
		}
		
		if(id>0){
			return "view/manage/userManage_UI";
		}else {
			model.addAttribute("addNewUser", "addNewUser");
			return "view/manage/addNewUser";
		}
	}
	
	@RequestMapping(value="/role.do")
	public String role(){
		
		return "view/manage/role";
	}
	
}
